package com.tg.app.view;

import android.app.Activity;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.appbase.custom.config.TGConfig;
import com.tange.module.core.wifi.scan.ApScanConfiguration;
import com.tg.app.R;


public  class WifiPopupWindow extends PopupWindow {
    private View contentView;
    private Activity activity;
    public WifiPopupWindow(View contentView, Activity context){
        super(contentView,
                RelativeLayout.LayoutParams.MATCH_PARENT,  RelativeLayout.LayoutParams.MATCH_PARENT, true);
        this.contentView = contentView;
        this.activity = context;
    }
    public void init(){
        TextView tips = contentView.findViewById(R.id.tv_ap_tips_setup_two_content);
        String tipsText = String.format(activity.getResources().getString(R.string.ap_tips_setup_two_description), ApScanConfiguration.INSTANCE.apNamePrefix());
        tips.setText(tipsText);
        setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                if(activity!=null){
                    WindowManager.LayoutParams params = activity.getWindow().getAttributes();
                    params.alpha = 1f;
                    activity.getWindow().setAttributes(params);
                }
            }
        });
        ImageButton close_btn = contentView.findViewById(R.id.add_close);
        close_btn.setOnClickListener(new View.OnClickListener() {
            @Override

            public void onClick(View v) {
                dismiss();
            }
        });
       setTouchable(true);
       setOutsideTouchable(false);
       setFocusable(false);
       setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });
    }
}
